package com.fs.wx;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.io.InputStream;

/**
 * 描述：微信支付配置信息
 */
@RefreshScope
@Component
public class WeWxConfig extends WXPayConfig {
    @Value("${wx.appid:wx338980444f83c67a}")
    private String appId;
    @Value("${wx.mchid:1586747601}")
    private String mchId;
    @Value("${wx.apikey:036cf468f23e4b04d82ea86578c3668a}")
    private String apiKey;

    /**
     * 公众账号ID:微信支付分配的公众账号ID（企业号corpid即为此appId）
     *
     * @return
     */
    @Override
    public String getAppID() {
        return appId;
    }

    /**
     * 商户号:微信支付分配的商户号
     *
     * @return
     */
    @Override
    public String getMchID() {
        System.out.println(mchId+" =======================");
        return mchId;
    }

    /**
     * @return
     */
    @Override
    public String getKey() {
        return apiKey;
    }

    @Override
    public InputStream getCertStream() {
        return null;
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 0;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 0;
    }

    public IWXPayDomain getWXPayDomain() {
        IWXPayDomain iwxPayDomain = new IWXPayDomain() {

            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }

            public DomainInfo getDomain(WXPayConfig config) {
                return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
        return iwxPayDomain;
    }
}